/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZLdapFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*     */ import com.zimbra.cs.ldap.ZSearchControls;
/*     */ import com.zimbra.cs.ldap.ZSearchResultEntry;
/*     */ import com.zimbra.cs.ldap.ZSearchResultEnumeration;
/*     */ import com.zimbra.cs.ldap.ZSearchScope;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapZLdapContext
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  53 */     provUtil = new LdapProvTestUtil();
/*  54 */     prov = provUtil.getProv();
/*  55 */     domain = provUtil.createDomain(baseDomainName());
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  60 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchPaged() throws Exception {
/*  65 */     int SIZE_LIMIT = 5;
/*     */     
/*  67 */     String base = "";
/*  68 */     ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
/*  69 */     String[] returnAttrs = { "objectClass" };
/*     */     
/*  71 */     final List<String> result = new ArrayList();
/*     */     
/*  73 */     SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor()
/*     */     {
/*     */       public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
/*  76 */         result.add(dn);
/*     */       }
/*     */       
/*  79 */     };
/*  80 */     SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, returnAttrs, SIZE_LIMIT, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
/*     */     
/*     */ 
/*     */ 
/*  84 */     boolean caughtException = false;
/*     */     
/*  86 */     ZLdapContext zlc = null;
/*     */     try {
/*  88 */       zlc = LdapClient.getContext(LdapUsage.UNITTEST);
/*  89 */       zlc.searchPaged(searchOptions);
/*     */     } catch (LdapException.LdapSizeLimitExceededException e) {
/*  91 */       caughtException = true;
/*     */     } finally {
/*  93 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */     
/*  96 */     Assert.assertTrue(caughtException);
/*  97 */     Assert.assertEquals(SIZE_LIMIT, result.size());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchDir() throws Exception {
/* 102 */     int SIZE_LIMIT = 5;
/*     */     
/* 104 */     String base = "";
/* 105 */     ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
/* 106 */     String[] returnAttrs = { "objectClass" };
/*     */     
/* 108 */     ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, SIZE_LIMIT, returnAttrs);
/*     */     
/*     */ 
/*     */ 
/* 112 */     int numFound = 0;
/* 113 */     boolean caughtException = false;
/*     */     
/* 115 */     ZLdapContext zlc = null;
/*     */     try {
/* 117 */       zlc = LdapClient.getContext(LdapUsage.UNITTEST);
/*     */       
/* 119 */       ZSearchResultEnumeration ne = zlc.searchDir(base, filter, searchControls);
/* 120 */       while (ne.hasMore()) {
/* 121 */         ZSearchResultEntry sr = ne.next();
/* 122 */         numFound++;
/*     */       }
/* 124 */       ne.close();
/*     */     }
/*     */     catch (LdapException.LdapSizeLimitExceededException e) {
/* 127 */       caughtException = true;
/*     */     } finally {
/* 129 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */     
/* 132 */     Assert.assertTrue(caughtException);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapZLdapContext.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */